import Vue from 'vue'
import VueRouter from 'vue-router'
const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
Vue.use(VueRouter)



const routes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/')
  },
  {
    path: '/',
    component: () => import('@/views/layout/'),
    children:[
      {
        path: '',
        name:'home',
        component: () => import('@/views/home/')
      },
      {
        path: '/qa',
        name:'qa',
        component: () => import('@/views/qa/')
      },
      {
        path: '/videos',
        name:'videos',
        component: () => import('@/views/videos/')
      },
      {
        path: '/my',
        name:'my',
        component: () => import('@/views/my/')
      }
    ]
  },
  // 搜索
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/search/')
  },
  // 文章详情
  {
    path: '/article/:articleId',
    name: 'article',
    component: () => import('@/views/article/'),
    // 把动态路由的参数映射到props属性上，在组件的props中接收
    props: true
  },
  {
    // 用户资料
    path: '/user/profile',
    name: 'user-profile',
    component: () => import('@/views/user-profile/')
  },
  //信息聊天
  {
    path: '/user/chat',
    name: 'user-chat',
    component: () => import('@/views/user-chat/')
  }

]

const router = new VueRouter({
  routes
})

export default router
